﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FlyHorse.LIMS.Model;
using FlyHorse.LIMS.WinApp.Utils;

namespace FlyHorse.LIMS.WinApp.DataManageForms.ReportProductForms
{
    public partial class FillMixDataForm : DevExpress.XtraEditors.XtraForm
    {
        BLL.ToolBll toolBll = new BLL.ToolBll();
        Action<ReportMix> _FillData;
        OJCB4Entities db = new OJCB4Entities();
        public FillMixDataForm(Action<ReportMix> FillData)
        {
            InitializeComponent();
            _FillData = FillData;
        }

        private void FillMixDataForm_Load(object sender, EventArgs e)
        {
            this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
            this.gridView1.OptionsBehavior.Editable = false;
            this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;

            //grid里的goods 下拉框
            //repositoryItemLookUpEdit1.DataSource = toolBll.GetAllGoodList();
            ////grid 取样位置
            //repositoryItemLookUpEdit2.DataSource = toolBll.GetMixSamplingPlaceList();
            ////grid 录入人
            //repositoryItemLookUpEdit5.DataSource = toolBll.GetAllLoginUersList();

        }

        private void barEditItem_Data_EditValueChanged(object sender, EventArgs e)
        {
            DateTime date = Convert.ToDateTime(this.barEditItem_Date.EditValue);
            DateTime yesterday = date.AddDays(-1);
            DateTime tomorrow = date.AddDays(1);

            splashScreenManager1.ShowWaitForm();
            var dataList = db.ReportMixes.AsNoTracking().Where(m => m.SendDate >= date && m.SendDate < tomorrow).OrderBy(m => m.SendDate);
            PagedList<ReportMix> pagedList = new PagedList<ReportMix>(dataList, 1, 99999999);
            this.gridControl1.DataSource = TransformReport.TransformMixReport(pagedList);
            splashScreenManager1.CloseWaitForm();
        }

        private void barLargeButtonItem_fill_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.gridView1.GetFocusedRowCellValue("ReportMixID") != null)
            {
                string id = Convert.ToString(this.gridView1.GetFocusedRowCellValue("ReportMixID"));
                ReportMix report = db.ReportMixes.Where(m => m.ReportMixID == id).FirstOrDefault();
                if (report != null)
                {
                    _FillData(report);
                    this.Close();
                }
            }
        }

        private void barEditItem_LotNo_EditValueChanged(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            var dataList = db.ReportMixes.AsNoTracking().Where(m => m.LotNO.Contains(this.barEditItem_LotNo.EditValue.ToString())).OrderByDescending(m => m.SendDate);
            PagedList<ReportMix> pagedList = new PagedList<ReportMix>(dataList, 1, 99999999);
            this.gridControl1.DataSource = TransformReport.TransformMixReport(pagedList);
            splashScreenManager1.CloseWaitForm();
        }

      
    }
}